package com.cy.ppj.dao.mapper.order;

import com.cy.ppj.model.domian.order.WithholdRecord;
import com.cy.ppj.model.enums.WithholdStatus;
import com.cy.ppj.model.vo.admin.statistics.CommissionAndWithholdStatisticsVO;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

@Mapper
public interface WithholdRecordMapper extends BaseMapper<WithholdRecord> {

    @Update("UPDATE t_withhold_record r SET r.`status`=#{status} WHERE r.`status`='PROCESSING' AND r.id=#{id}")
    int updateStatus(@Param("id") Long id, @Param("status") WithholdStatus status);

    @Select("SELECT * FROM t_withhold_record wr WHERE wr.order_id=#{orderId} AND wr.`status`='PROCESSING'")
    WithholdRecord selectProcessingByOrderId(@Param("orderId") Long orderId);
    
    @Select("SELECT IFNULL(SUM(amount), 0) as withholdAmount, COUNT(id) as withholdCount FROM t_withhold_record WHERE `status` = 'SUCCESS' ")
    CommissionAndWithholdStatisticsVO selectWithholdStatisticsVO();
}
